package com.cip.admin.dao.impl;

import java.util.List;

import com.cip.admin.dao.CIPLoggerDAO;
import com.cip.admin.model.CIPLogger;
import com.cip.admin.model.Institute;
import com.cip.master.model.Academic;

public class CIPLoggerDAOImpl extends CipHibernateDAOSupport implements CIPLoggerDAO {
	
	public List<String> getAllLoggedUserList() throws Exception{
		String query="select cipLogger.loginUser from CIPLogger as cipLogger where cipLogger.status='Active'";
		return getCipHibernateTemplate().find(query);
	}
	
	public List<String> getAllLoggedFriendsList(int requestFriendId) throws Exception{
		String query="select friends.responseFriend.username from Friends as friends, User as user where friends.status='Active' and user.username=friends.responseFriend.username and user.loginStatus='Active' and friends.requestFriend='"+requestFriendId+"'";
		return getCipHibernateTemplate().find(query);
	}
	
	public CIPLogger saveOrUpdateLogger(CIPLogger cipLogger) throws Exception {
		getHibernateTemplate().saveOrUpdate(cipLogger);
		return cipLogger;
	}
	
	public CIPLogger getCIPLoggerByUser(String loginUser) throws Exception{
		String query="select cipLog from CIPLogger as cipLog where cipLog.loginUser='"+loginUser+"'";
		List<CIPLogger> logList = getCipHibernateTemplate().find(query);
		if(logList.size() > 0){
			return logList.get(0);
		}
		return null;
	}
	
	public CIPLogger getCIPLoggerById(int loginId) throws Exception{
		String query="select cipLog from CIPLogger as cipLog where cipLog.loginUser='"+loginId+"'";
		List<CIPLogger> logList = getCipHibernateTemplate().find(query);
		if(logList.size() > 0){
			return logList.get(0);
		}
		return null;
	}

}
